/**
 * Created by zhaojm on 15/3/21.
 */
game.UILayer = cc.Layer.extend({
    _text : null,
    ctor:function(){
        this._super();
        this._text = cc.LabelTTF.create('0m', 'Arial', 18);
        this._text.setPosition(cc.p(cc.winSize.width * 0.8, cc.winSize.height * 0.95));
        this._text.setAnchorPoint(cc.p(0, 0.5));
        this.addChild(this._text);
    },

    setText : function(num){
        this._text.setString((num * 10).toFixed(0) + 'm');
    },





    startGuide:function(){
        //this.isCanMove = false;
        //this.hero.isCanMove = false;
        this.guideTask =0;


        //this._colorLayer = new game.GuideLayer();
        //this.addChild(this._colorLayer);

        this._bg = new cc.Sprite(cc.spriteFrameCache.getSpriteFrame('guide_bg_0.png'));
        this._bg.setPosition(cc.winSize.width * 0.5, cc.winSize.height * 0.5);
        this.addChild(this._bg);

        this.parent._hubLayer.setGuideButton(this.guideTask);


        //this._light = new cc.Sprite(cc.spriteFrameCache.getSpriteFrame('guide/light.png'));
        ////this._light.setScale(cc.winSize.width / this._guideSprite.getContentSize().width);
        //this._light.setPosition(cc.p(cc.winSize.width / 2, cc.winSize.height * 0.5));
        ////this._light.setBlendFunc(gl.SRC_ALPHA, gl.ONE);
        ////this._guideSprite.setAnchorPoint(cc.p(0, 0));
        //this.addChild(this._light);

        //this._hand = new cc.Sprite(cc.spriteFrameCache.getSpriteFrame('guide/hand.png'));
        //this.addChild(this._hand);
        //this._hand.setAnchorPoint(cc.p(0, 1));
        //this._hand.setPosition(cc.winSize.width / 2, cc.winSize.height * 0.4);

        //this._guideTxt = new cc.Sprite(cc.spriteFrameCache.getSpriteFrame('guide/text0.png'));
        //this.addChild(this._guideTxt);
        //this._guideTxt.setPosition(cc.winSize.width * 0.5, cc.winSize.height * 0.7);

        //var buttonFrame = cc.spriteFrameCache.getSpriteFrame('guide/next.png');
        //this._guideButton = new cc.MenuItemImage(buttonFrame,buttonFrame,buttonFrame, this.onGuideButtonCallback, this);
        ////this._guideButton.setAnchorPoint(cc.p(1, 1));
        ////this.addChild(this._guideButton, 5);
        //this._guideButton.setPosition(cc.p(cc.winSize.width / 2, cc.winSize.height * 0.4));
        //this._menu = new cc.Menu(this._guideButton);
        //this._menu.setPosition(cc.p(0, 0));
        //this.addChild(this._menu, 5);

        //this.guideLayer.setSpriteVisible(true);
        //this.guideLayer.setSpritePosition(cc.p(cc.winSize.width / 2 - this.getPositionX(), cc.winSize.height / 2));
        //this.guideLayer.setEnabled(true);
    },

    onGuideButtonCallback:function(){

        //cc.log('button call back');
        var self = this;

        if(self.guideTask == 0){
            self.beginGuide2();
        }else if(self.guideTask == 1){
            self.beginGuide3();
        } else if(self.guideTask == 2){
        //    self.beginGuide4();
        //}else if(self.guideTask == 3){
            self.onGuideTask2();
        }
    },


    beginGuide2 : function(){
        //this.isCanMove = false;
        //this.hero.isCanMove = false;
        this.guideTask = 1;
        // TODO 手 点击可以跳得更高
        //this._guideSprite.setSpriteFrame(cc.spriteFrameCache.getSpriteFrame('guide0.png'));
        //this._guideSprite.setPositionX(cc.winSize.width / 2 - this.getPositionX());
        //this._guideSprite.setVisible(true);
        //this._guideButton.setVisible(true);
        //this._guideButton.setPosition(cc.p(cc.winSize.width - 10 - this.getPositionX(), cc.winSize.height - 10));
        //this._guideTxt.setSpriteFrame(cc.spriteFrameCache.getSpriteFrame('guide/text1.png'));

        //this.touchLayer.setTouchEnabled(false);
        //this.guideLayer.setSpriteVisible(true);
        //this.guideLayer.setSpritePosition(cc.p(cc.winSize.width / 2 - this.getPositionX(), cc.winSize.height / 2));
        //this.guideLayer.setEnabled(true);
        this.parent._hubLayer.setGuideButton(this.guideTask);
        this._bg.setSpriteFrame(cc.spriteFrameCache.getSpriteFrame('guide_bg_1.png'));
    },
    beginGuide3:function(){
        //this.isCanMove = false;
        //this.hero.isCanMove = false;
        this.guideTask = 2;
        // TODO 点击开始游戏吧
        //this._guideSprite.setSpriteFrame(cc.spriteFrameCache.getSpriteFrame('guide2.png'));
        //this._guideSprite.setPositionX(cc.winSize.width / 2 - this.getPositionX());
        //this._guideSprite.setVisible(true);
        //this._guideButton.setVisible(true);
        //this._guideButton.setPosition(cc.p(cc.winSize.width - 10 - this.getPositionX(), cc.winSize.height - 10));
        //this.touchLayer.setTouchEnabled(false);
        //this.guideLayer.setSpriteVisible(true);
        //this.guideLayer.setSpritePosition(cc.p(cc.winSize.width / 2 - this.getPositionX(), cc.winSize.height / 2));
        //this.guideLayer.setEnabled(true);
        //var okframe = cc.spriteFrameCache.getSpriteFrame('guide/ok.png');
        //this._guideButton.setDisabledSpriteFrame(okframe);
        //this._guideButton.setSelectedSpriteFrame(okframe);
        //this._guideButton.setNormalSpriteFrame(okframe);
        //this._guideTxt.setSpriteFrame(cc.spriteFrameCache.getSpriteFrame('guide/text2.png'));
        this.parent._hubLayer.setGuideButton(this.guideTask);
        this._bg.setSpriteFrame(cc.spriteFrameCache.getSpriteFrame('guide_bg_2.png'));
    },
    beginGuide4:function(){
        //this.isCanMove = false;
        //this.hero.isCanMove = false;
        this.guideTask = 3;
        // TODO 点击开始游戏吧
        //this._guideSprite.setSpriteFrame(cc.spriteFrameCache.getSpriteFrame('guide2.png'));
        //this._guideSprite.setPositionX(cc.winSize.width / 2 - this.getPositionX());
        //this._guideSprite.setVisible(true);
        //this._guideButton.setVisible(true);
        //this._guideButton.setPosition(cc.p(cc.winSize.width - 10 - this.getPositionX(), cc.winSize.height - 10));
        //this.touchLayer.setTouchEnabled(false);
        //this.guideLayer.setSpriteVisible(true);
        //this.guideLayer.setSpritePosition(cc.p(cc.winSize.width / 2 - this.getPositionX(), cc.winSize.height / 2));
        //this.guideLayer.setEnabled(true);
        //var okframe = cc.spriteFrameCache.getSpriteFrame('guide/ok.png');
        //this._guideButton.setDisabledSpriteFrame(okframe);
        //this._guideButton.setSelectedSpriteFrame(okframe);
        //this._guideButton.setNormalSpriteFrame(okframe);
        //this._guideTxt.setSpriteFrame(cc.spriteFrameCache.getSpriteFrame('guide/text3.png'));
        this.parent._hubLayer.setGuideButton(this.guideTask);
        //this._bg.setSpriteFrame(cc.spriteFrameCache.getSpriteFrame('guide/bg_3.png'));
    },


    //onGuideTask0 : function(){
    //    this.isCanMove = true;
    //    this.hero.isCanMove = true;
    //    this.hero.isGuideTask = 0;
    //    this._guideSprite.setVisible(false);
    //    this._guideButton.setVisible(false);
    //
    //    //this.guideLayer.setSpriteVisible(false);
    //    //this.guideLayer.setEnabled(false);
    //},
    //
    //onGuideTask1:function(){
    //    this.isCanMove = true;
    //    this.hero.isCanMove = true;
    //    this.hero.isGuideTask = 1;
    //    this._guideSprite.setVisible(false);
    //    this._guideButton.setVisible(false);
    //    //this.guideLayer.setSpriteVisible(false);
    //    //this.guideLayer.setEnabled(false);
    //},
    onGuideTask2:function(){
        this.parent._isGuide = false;
        this.parent._bear.setScale(0.3);
        //this.parent.mainLayer.hero.isCanMove = true;
        //this.hero.isGuideTask = -1;
        //this.touchLayer.guideTask = -1;
        //this._hand.removeFromParent();
        this._bg.removeFromParent();
        //this._light.removeFromParent();
        //this._colorLayer.removeFromParent();
        //this._guideButton.removeFromParent();
        //this._guideTxt.removeFromParent();
        //this.parent._hubLayer.setTouchEnabled(true);
        cc.sys.localStorage.setItem('bear_guide', '1');
    },



});